package com.wangshuqi.boot.result;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2002204089434671640L;

	/**
	 * 数据结果
	 */
	private T data;
	
	/**
	 * 执行结果
	 */
	private boolean success = true;

	/**
	 * 结果信息
	 */
	private String msg;

	/**
	 * 状态码
	 */
	private int resultCode;
	
	public static<T> Result<T> success(T data) {
		Result<T> result = new Result<T>();
		result.setData(data);
		result.setResultCode(200);
		return result;
	}
	
	public static<T> Result<T> errorResult(int errorCode, String errorMsg) {
		Result<T> result = new Result<T>();
		result.setSuccess(false);
		result.setMsg(errorMsg);
		result.setResultCode(errorCode);
		return result;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public int getResultCode() {
		return resultCode;
	}

	public void setResultCode(int resultCode) {
		this.resultCode = resultCode;
	}

	@Override
	public String toString() {
		return "Result [data=" + data + ", success=" + success + ", msg=" + msg
				+ ", resultCode=" + resultCode + "]";
	}
}
